package cn.sumpu.app.coolsk.biz.impl;



//import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.sumpu.app.coolsk.biz.ConfigBiz;
import cn.sumpu.app.coolsk.dao.ConfigDao;
import cn.sumpu.app.coolsk.domain.Config;
import cn.sumpu.app.coolsk.exception.AppBusinessException;
import cn.sumpu.toolkit.common.page.PageModel;

public class ConfigBizImpl implements ConfigBiz{

	private ConfigDao configDao;
	
	public void setConfigDao(ConfigDao configDao) {
		this.configDao = configDao;
	}

	@Override
	public PageModel getConfigList(Integer page, Integer pagesize,String key) throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		int size = pagesize;
		map.put("startId", (page - 1) * size);
		map.put("pageSize", size);
		map.put("key", key);
		int count = configDao.getConfigCount(map);
		PageModel pm = new PageModel();
		pm.setCurrentPage(page);
		pm.setList(configDao.getConfig(map));
		pm.setPageSize(size);
		pm.setTotalRecord(count);
		pm.setTotalPage((count + size - 1) / size);
		return pm;
	}

	@Override
	public Config getConfigById(String key) throws AppBusinessException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("key", key);
		List<Config> tlist = configDao.getConfig(map);
		if(tlist != null && tlist.size() > 0){
			return tlist.get(0);
		}
		return null;
	}

	@Override
	public boolean saveConfig(Config config) throws AppBusinessException {
		configDao.updateConfig(config);
		return true;
	}
	
	

}
